<%@ page import="java.sql.Connection" %>
<%@ page import="com.example.util.DBUtil" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %><%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2021/11/23
  Time: 20:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>查询班级信息</title>
</head>
<body>
获取到的姓名为:<%=session.getAttribute("cname")%><br>
<%
    try {
        Connection connection = DBUtil.getConnection();
        String sql = "select * from c_user";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            String cname = resultSet.getString("cname");
            if(session.getAttribute("cname").equals(cname)) {
                out.println("班级名称:"+session.getAttribute("cname")+"的信息存在,查询成功!");
                cname = resultSet.getString("cname");
                String cgrade = resultSet.getString("cgrade");
                String ctname = resultSet.getString("ctname");
                String cflag = resultSet.getString("cflag");
                String cnum = resultSet.getString("cnum");
                out.println("<br>");
                out.println("查询的信息如下所示:");
                out.println("<br>");
                out.println("班级名称为:"+cname);
                out.println("<br>");
                out.println("年级为:"+cgrade);
                out.println("<br>");
                out.println("班主任名称为:"+ctname);
                out.println("<br>");
                out.println("班级口号为:"+cflag);
                out.println("<br>");
                out.println("班级人数为:"+cnum);
                break;
            }
        }
    }catch(SQLException e){
        e.printStackTrace();
    }
%>
</body>
</html>
